import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["organizationId"],
    _excluded2 = ["organizationId"];

/**
 * template - 通用模板
 * @since 2018-08-28
 * @version 0.0.1

 */
import request from 'utils/request';
import { CPAAS_IMP, CPAAS_PLATFORM } from 'utils/config';
import { parseParameters, getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
var tenantId = getCurrentOrganizationId();

function templateHeaderApi() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/template-headers") : "template-headers";
}

function templateLineApi() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/template-lines") : "template-lines";
}
/**
 * 查询模板头数据列表
 * @async
 * @function query
 * @param {Object} params - 查询参数
 */


export function query(_x) {
  return _query.apply(this, arguments);
}
/**
 * 查询模板单条头数据信息
 * @async
 * @function queryOneHeader
 * @param {Object} params - 查询参数
 */

function _query() {
  _query = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var organizationId, otherParams, param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            organizationId = params.organizationId, otherParams = _objectWithoutProperties(params, _excluded);
            param = parseParameters(otherParams);
            return _context.abrupt("return", request("".concat(CPAAS_IMP, "/v1/").concat(templateHeaderApi()), {
              method: 'GET',
              query: param
            }));

          case 3:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _query.apply(this, arguments);
}

export function queryOneHeader(_x2) {
  return _queryOneHeader.apply(this, arguments);
}
/**
 * 更新头数据信息
 * @async
 * @function update
 * @param {Object} params - 查询参数
 */

function _queryOneHeader() {
  _queryOneHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var templateId;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            templateId = params.templateId;
            return _context2.abrupt("return", request("".concat(CPAAS_IMP, "/v1/").concat(templateHeaderApi(), "/").concat(templateId), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _queryOneHeader.apply(this, arguments);
}

export function update(_x3) {
  return _update.apply(this, arguments);
}
/**
 * 创建头数据
 * @async
 * @function create
 * @param {Object} params - 查询参数
 */

function _update() {
  _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_IMP, "/v1/").concat(templateHeaderApi()), {
              method: 'PUT',
              body: _objectSpread({
                tenantId: tenantId
              }, params)
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _update.apply(this, arguments);
}

export function create(_x4) {
  return _create.apply(this, arguments);
}
/**
 * 移除单条头数据
 * @async
 * @function removeHeader
 * @param {Object} params - 查询参数
 */

function _create() {
  _create = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_IMP, "/v1/").concat(templateHeaderApi()), {
              method: 'POST',
              body: _objectSpread({
                tenantId: tenantId
              }, params)
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _create.apply(this, arguments);
}

export function removeHeader(_x5) {
  return _removeHeader.apply(this, arguments);
}
/**
 * 获取模板列列表数据
 * @async
 * @function fetchColumnList
 * @param {Object} params - 查询参数
 */

function _removeHeader() {
  _removeHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    var organizationId, otherParams;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            organizationId = params.organizationId, otherParams = _objectWithoutProperties(params, _excluded2);
            return _context5.abrupt("return", request("".concat(CPAAS_IMP, "/v1/").concat(templateHeaderApi()), {
              method: 'DELETE',
              body: otherParams
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _removeHeader.apply(this, arguments);
}

export function fetchColumnList(_x6) {
  return _fetchColumnList.apply(this, arguments);
}
/**
 * 获取模板列详情数据
 * @async
 * @function fetchColumnDetail
 * @param {Object} params - 查询参数
 */

function _fetchColumnList() {
  _fetchColumnList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(CPAAS_IMP, "/v1/").concat(templateLineApi()), {
              method: 'GET',
              query: _objectSpread({
                tenantId: tenantId
              }, params)
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _fetchColumnList.apply(this, arguments);
}

export function fetchColumnDetail(_x7) {
  return _fetchColumnDetail.apply(this, arguments);
}
/**
 * 创建模板列
 * @async
 * @function createColumn
 * @param {Object} params - 查询参数
 */

function _fetchColumnDetail() {
  _fetchColumnDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request("".concat(CPAAS_IMP, "/v1/").concat(templateLineApi(), "/").concat(params.id), {
              method: 'GET',
              query: {
                tenantId: tenantId
              }
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _fetchColumnDetail.apply(this, arguments);
}

export function createColumn(_x8) {
  return _createColumn.apply(this, arguments);
}
/**
 * 更新模板列数据
 * @async
 * @function updateColumn
 * @param {Object} params - 查询参数
 */

function _createColumn() {
  _createColumn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            return _context8.abrupt("return", request("".concat(CPAAS_IMP, "/v1/").concat(templateLineApi()), {
              method: 'POST',
              body: _objectSpread({
                tenantId: tenantId
              }, params)
            }));

          case 1:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _createColumn.apply(this, arguments);
}

export function updateColumn(_x9) {
  return _updateColumn.apply(this, arguments);
}
/**
 * 删除模板列数据
 * @async
 * @function updateColumn
 * @param {Object} params - 查询参数
 */

function _updateColumn() {
  _updateColumn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(params) {
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            return _context9.abrupt("return", request("".concat(CPAAS_IMP, "/v1/").concat(templateLineApi()), {
              method: 'PUT',
              body: _objectSpread({
                tenantId: tenantId
              }, params)
            }));

          case 1:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _updateColumn.apply(this, arguments);
}

export function deleteColumn(_x10) {
  return _deleteColumn.apply(this, arguments);
}
/**
 * 查询值集
 * @async
 * @function queryCode
 * @param {object} params - 查询条件
 * @param {!string} param.lovCode - 查询条件
 * @returns {object} fetch Promise
 */

function _deleteColumn() {
  _deleteColumn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(params) {
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            return _context10.abrupt("return", request("".concat(CPAAS_IMP, "/v1/").concat(templateLineApi()), {
              method: 'DELETE',
              body: _objectSpread({
                tenantId: tenantId
              }, params)
            }));

          case 1:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _deleteColumn.apply(this, arguments);
}

export function queryCode() {
  return _queryCode.apply(this, arguments);
}

function _queryCode() {
  _queryCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
    var params,
        _args11 = arguments;
    return _regeneratorRuntime.wrap(function _callee11$(_context11) {
      while (1) {
        switch (_context11.prev = _context11.next) {
          case 0:
            params = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : {};
            return _context11.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/lovs/value"), {
              query: params
            }));

          case 2:
          case "end":
            return _context11.stop();
        }
      }
    }, _callee11);
  }));
  return _queryCode.apply(this, arguments);
}